// 管理员角色功能实现
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include "../util/FileManage.h"
#include "../util/InputFormat.h"
#include "../util/LinkedList.h"
#include "../manage/StaffManage.h"
#include "../manage/TableManage.h"
#include "../manage/DishManage.h"
#include "RoleOfAdministrator.h"

// 输出管理员功能界面  以及相关功能函数
// 返回一个整型数字，判断注销还是退出
int UiOfAdministrator()
{
    int chooseItem;
    void (*allFuctionUi[3])() = {UiOfStaffManage, UiOfMenuManage, UiOfTableManage};
    while (1)
    {
        system("cls");
        printf("\n\n\t\t*************** 管理员功能界面 ***************\n\n\n");
        printf("\t\t\t\t 1: 员工管理\n\n");
        printf("\t\t\t\t 2: 菜单管理\n\n");
        printf("\t\t\t\t 3: 餐桌管理\n\n");
        printf("\t\t\t\t 4: 注销\n\n");
        printf("\t\t\t\t 5: 退出\n\n\n");
        printf("\t\t************************************************\n\n");
        printf("\t\t### 请输入您要选择的功能：");
        chooseItem = FormatInputString(NULL, '1', '5', 1, 2);
        if (chooseItem > 0 && chooseItem < 4)
        {
            allFuctionUi[chooseItem - 1]();
        }
        else if (chooseItem == 4)
        {
            return 0;
        }
        else if (chooseItem == 5)
        {
            return 1;
        }
    }
}
//  员工管理功能界面
void UiOfStaffManage()
{
    char staffDBPath[] = "staffInfos.txt";
    FILE *filePointer;
    ListPointer nodeHead;
    int chooseItem;
    int count;
    filePointer = FileOpen(staffDBPath);
    nodeHead = FileRead(filePointer, sizeof(struct Staff));
    count = LinkedListCount(nodeHead);
    while (1)
    {
        system("cls");
        printf("\n\n\t\t*************** 员工管理界面 ***************\n\n\n");
        printf("\t\t\t      1: 添加员工信息\n\n");
        printf("\t\t\t      2: 删除员工信息\n\n");
        printf("\t\t\t      3: 修改员工信息\n\n");
        printf("\t\t\t      4: 查询员工信息\n\n");
        printf("\t\t\t      5: 返回\n\n\n");
        printf("\t\t*******************************************\n\n");
        printf("\t\t=== > 请输入您要操作的功能：");
        chooseItem = FormatInputString(NULL, '1', '5', 1, 2);
        switch (chooseItem)
        {
        case 1:
            LinkedListPrint(nodeHead, StaffInfoPrint);
            FileAdd(filePointer, nodeHead, sizeof(struct Staff), StaffAdd);
            LinkedListPrint(nodeHead, StaffInfoPrint);
            break;
        case 2:
            LinkedListPrint(nodeHead, StaffInfoPrint);
            FileRemove(filePointer, nodeHead, sizeof(struct Staff), StaffRemove);
            nodeHead = FileRead(filePointer, sizeof(struct Staff));
            LinkedListPrint(nodeHead, StaffInfoPrint);
            break;
        case 3:
            LinkedListPrint(nodeHead, StaffInfoPrint);
            FileUpdate(filePointer, nodeHead, sizeof(struct Staff), StaffUpdate);
            nodeHead = FileRead(filePointer, sizeof(struct Staff));
            LinkedListPrint(nodeHead, StaffInfoPrint);
            break;
        case 4:
            StaffSearch(nodeHead);
            break;
        case 5:
            break;
        }
        if (chooseItem == 5)
        {
            break;
        }
        else
        {
            printf("\n\t\t#@# 按<Esc>键返回...");
            while (getch() != 27)
            {
            }
        }
    }
    LinkedListFree(nodeHead);
}
//  餐桌管理功能界面
void UiOfTableManage()
{
    char tableDBPath[] = "tableInfos.txt";
    FILE *filePointer;
    ListPointer nodeHead;
    int chooseItem;
    filePointer = FileOpen(tableDBPath);
    nodeHead = FileRead(filePointer, sizeof(struct Table));
    while (1)
    {
        system("cls");
        printf("\n\n\t\t*************** 餐桌管理界面 ***************\n\n\n");
        printf("\t\t\t      1: 添加餐桌信息\n\n");
        printf("\t\t\t      2: 删除餐桌信息\n\n");
        printf("\t\t\t      3: 修改餐桌信息\n\n");
        printf("\t\t\t      4: 查询餐桌信息\n\n");
        printf("\t\t\t      5: 返回\n\n");
        printf("\t\t*******************************************\n\n");
        printf("\t\t=== > 请输入您要操作的功能：");
        chooseItem = FormatInputString(NULL, '1', '5', 1, 2);
        switch (chooseItem)
        {
        case 1:
            LinkedListPrint(nodeHead, TablePrint);
            FileAdd(filePointer, nodeHead, sizeof(struct Table), TableAdd);
            nodeHead = FileRead(filePointer, sizeof(struct Table));
            LinkedListPrint(nodeHead, TablePrint);
            break;
        case 2:
            LinkedListPrint(nodeHead, TablePrint);
            FileRemove(filePointer, nodeHead, sizeof(struct Table), TableRemove);
            nodeHead = FileRead(filePointer, sizeof(struct Table));
            LinkedListPrint(nodeHead, TablePrint);
            break;
        case 3:
            LinkedListPrint(nodeHead, TablePrint);
            FileUpdate(filePointer, nodeHead, sizeof(struct Table), TableUpdate);
            nodeHead = FileRead(filePointer, sizeof(struct Table));
            LinkedListPrint(nodeHead, TablePrint);
            break;
        case 4:
            TableSearch(nodeHead, 3, 4);
            break;
        case 5:
            break;
        }
        if (chooseItem == 5)
        {
            break;
        }
        else
        {
            printf("\n\t\t#@# 按[ Esc ]键返回...");
            while (getch() != 27)
            {
            }
        }
    }
    LinkedListFree(nodeHead);
}
//  菜单管理功能界面
void UiOfMenuManage()
{
    char menuDBPath[] = "dishMenus.txt";
    FILE *filePointer;
    ListPointer nodeHead;
    int chooseItem;
    filePointer = FileOpen(menuDBPath);
    nodeHead = FileRead(filePointer, sizeof(struct Menu));
    while (1)
    {
        system("cls");
        printf("\n\n\t\t*************** 菜单管理界面 ***************\n\n\n");
        printf("\t\t\t      1: 增加菜单信息\n\n");
        printf("\t\t\t      2: 删除菜单信息\n\n");
        printf("\t\t\t      3: 修改菜单信息\n\n");
        printf("\t\t\t      4: 查询菜单信息\n\n");
        printf("\t\t\t      5: 返回\n\n");
        printf("\t\t*******************************************\n\n");
        printf("\t\t=== > 请输入您要操作的功能：");
        chooseItem = FormatInputString(NULL, '1', '5', 1, 2);
        switch (chooseItem)
        {
        case 1:
            LinkedListPrint(nodeHead, MenuPrint);
            FileAdd(filePointer, nodeHead, sizeof(struct Menu), MenuAdd);
            nodeHead = FileRead(filePointer, sizeof(struct Menu));
            LinkedListPrint(nodeHead, MenuPrint);
            break;
        case 2:
            LinkedListPrint(nodeHead, MenuPrint);
            FileDelete(filePointer, menuDBPath, nodeHead, sizeof(struct Menu), MenuDelete);
            LinkedListPrint(nodeHead, MenuPrint);
            break;
        case 3:
            LinkedListPrint(nodeHead, MenuPrint);
            FileUpdate(filePointer, nodeHead, sizeof(struct Menu), MenuUpdate);
            nodeHead = FileRead(filePointer, sizeof(struct Menu));
            LinkedListPrint(nodeHead, MenuPrint);
            break;
        case 4:
            MenuSearch(nodeHead);
            break;
        case 5:
            break;
        }
        if (chooseItem == 5)
        {
            break;
        }
        else
        {
            printf("\n\t\t#@# 按[ Esc ]键返回...");
            while (getch() != 27)
            {
            }
        }
    }
    LinkedListFree(nodeHead);
}
